home *** CD-ROM | disk | FTP | other *** search
-
- // JavaScript sample demonstrating how to create various GUI objects.
- // Copyrights 2002, Realsoft Graphics Oy
-
- // --- include java script classes ---
-
- include("oops/r3button.js");
- include("oops/r3window.js");
- include("oops/r3packer.js");
- include("oops/r3slider.js");
- include("oops/r3string.js");
- include("oops/r3checkb.js");
- include("oops/r3text.js");
- include("oops/r3cycle.js");
- include("oops/r3listv.js");
- include("real/gadget/r3vectg.js");
- include("real/gadget/r3floatg.js");
-
-
- {
-
- // --- Callback functions ---
-
- function mySliderHook(obj, event, value)
- {
- if(event == R3OGM_GADGETDOWN)
- obj.info.SetText("Down = " + value);
- else if(event == R3OGM_GADGETSCROLL)
- obj.info.SetText("Scroll = " + value);
- else if(event == R3OGM_GADGETUP)
- obj.info.SetText("Up = " + value);
- }
-
- function myStringHook(obj, event, value)
- {
- if(event == R3OGM_GADGETUP)
- obj.info.SetText("You entered string " + value);
- }
-
- function myButtonHook(obj, event, value)
- {
- sName = obj.GetText();
-
- if(event == R3OGM_GADGETUP)
- obj.info.SetText(sName + " clicked");
- }
-
- function myCheckboxHook(obj, event, value)
- {
- if(value == TRUE)
- obj.info.SetText("Check box checked");
- else
- obj.info.SetText("Check box cleared");
- }
-
- function myVectorHook(obj, event, value)
- {
- if(event == R3OGM_GADGETUP)
- obj.info.SetText("Vector [" + value.x + ", " + value.y + ", " + value.z + "] entered");
- }
-
- function myDuplicateHook(obj, event, value)
- {
- var v;
-
- v = obj.vector.GetValue(); // fetch the current value
- v.fmul(2.0); // multiply by two
- obj.vector.SetValue(v); // set back
- obj.info.SetText("Current value duplicated");
- }
-
- function myResetHook(obj, event, value)
- {
- obj.info.SetText("Welcome to JavaScript");
-
- v = new r3Vect(0, 0, 0);
- obj.vector.SetValue(v);
- }
-
- function myListviewHook(obj, event, value)
- {
- obj.info.SetText("Selected " + value);
- }
-
- // --- create a new window, as usual ---
-
- window = new r3Window(R3WGA_Parent, _r3gui,
- R3WGA_Left, 200,
- R3WGA_Top, 100,
- R3WA_Title, "Callback Sample",
- R3WA_ReportCloseWindow, TRUE,
- R3WA_ReportNewSize, TRUE);
-
-
- // --- create couple of gadgets with callbacks ---
-
- slider = new r3Slider(R3WGA_Parent, window,
- R3GA_Text, "My slider",
- R3GA_ToolTip, "Slider example",
- R3RA_Hook, mySliderHook,
- R3GSLA_Level, 20,
- R3GSLA_Min, 0,
- R3GSLA_Max, 100);
-
- string = new r3String(R3WGA_Parent, window,
- R3GA_Text, "String",
- R3GA_ToolTip, "Enter string to this field",
- R3GSA_String, "This is a string",
- R3RA_Hook, myStringHook);
-
- checkbox = new r3Checkbox(R3WGA_Parent, window,
- R3RA_Hook, myCheckboxHook,
- R3GA_Text, "Check box",
- R3GA_ToolTip, "This is a tool tip",
- R3GCBA_Checked, TRUE); // make it checked
-
- vector = new r3Vectorgadget(R3GA_Text, "Vector",
- R3RA_Hook, myVectorHook,
- R3VCGA_Vector, new r3Vect(0.1, 0.2, 0.0), // current value
- R3WGA_Parent, window);
-
- info = new r3Text(R3WGA_Parent, window,
- R3GA_Text, "Info",
- R3GTA_Text, "Welcome to JavaScript", // current value
- R3GTA_Border, TRUE);
-
- button = new r3Button(R3GA_Text, "My button",
- R3RA_Hook, myButtonHook,
- R3WGA_Parent, window);
-
- button2 = new r3Button(R3GA_Text, "Duplicate",
- R3RA_Hook, myDuplicateHook,
- R3WGA_Parent, window);
-
- button3 = new r3Button(R3GA_Text, "Reset",
- R3RA_Hook, myResetHook,
- R3WGA_Parent, window);
-
-
- list = new r3List();
- list.addhead(new r3Root(R3RA_Name, "Monday"));
- list.addhead(new r3Root(R3RA_Name, "Tuesday"));
- list.addhead(new r3Root(R3RA_Name, "Wednesday"));
-
- listv = new r3Listview(R3GA_Text, "List View",
- R3RA_Hook, myListviewHook,
- R3GLVA_List, list,
- R3WGA_Parent, window);
-
-
-
- // --- Design layout for the GUI ----
-
- packer = new r3Packer(R3PA_Orientation, R3PAOF_VERTICAL);
-
- packer.ADD(R3PAPF_FILLX, R3PAAF_ALIGN, slider);
- packer.ADD(R3PAPF_FILLX, R3PAAF_ALIGN, string);
- packer.ADD(R3PAPF_FILLX, R3PAAF_ALIGN, vector);
- packer.ADD(0, R3PAAF_ALIGN, checkbox);
- packer.ADD(R3PAPF_FILLX, R3PAAF_ALIGN, info);
- packer.ADD(R3PAPF_FILLX | R3PAPF_FILLY, 0, listv);
-
- // put buttons into a horizontal sub packer
- subp = new r3Packer(R3PA_Orientation, R3PAOF_HORIZONTAL);
- subp.ADD(R3PAPF_FILLX, 0, button);
- subp.ADD(R3PAPF_FILLX, 0, button2);
- subp.ADD(R3PAPF_FILLX, 0, button3);
- packer.ADD(R3PAPF_FILLX, 0, subp);
-
- window.SetGmanager(packer);
-
- // add 'info' gadget to all gadgets so that they can print
- // some information to the read only text gadget from their callbacks
- slider.info = info;
- button.info = info;
- checkbox.info = info;
- string.info = info;
- vector.info = info;
- listv.info = info;
- button2.vector = vector;
- button2.info = info;
- button3.vector = vector;
- button3.info = vector;
-
- // --- compute native size, show ---
-
- window.FIT(R3WFP_BESTFIT);
- window.REALIZE();
- }
-
-